//
//  AcceptAPI.swift
//  ShareUmbrella
//
//  Created by niupark on 2017/9/17.
//  Copyright © 2017年 尧尚信息科技. All rights reserved.
//

import Moya
import YSKit

public enum AcceptAPI: YSTargetRequestable {
    
    case askForHelpAction(token: String, from:[String:Any], to: [String:Any])
    case stopAskForHelpAction(token: String, helpid: String)
    case terminatHelpAction(token: String)
    case startRouteAction(token: String, helpid: String)
    case stopRouteAction(token: String, helpid: String)
    case commentAction(token: String, star: Float, content: String, helpId: String)

    
    /// 请求的URL分别写在API内部
    fileprivate struct RequestURL {
        // MARK: Market
        static let askForHelpAction = "/u4uapi/Index/AskForHelpAction"
        static let stopAskForHelpAction = "/u4uapi/Index/StopAskForHelpAction"
        static let terminatHelpAction = "/u4uapi/Index/TerminatHelpAction"
        static let startRouteAction = "/u4uapi/Index/StartRouteAction"
        static let stopRouteAction = "/u4uapi/Index/StopRouteAction"
        static let commentAction = "/u4uapi/Index/CommentHelperAction"
    }
    
    public var api: YSTargetRequest {
        
        switch self {
            
        case .askForHelpAction(let token, let from , let to):
            var parameters: [String: Any] = [:]
            parameters["token"] = token
            parameters["from"] = from
            parameters["to"] = to

            return YSTargetRequest(path: RequestURL.askForHelpAction,
                                   method: .post,
                                   parameters: parameters
            )
            
        case .stopAskForHelpAction(let token, let helpid):
            var parameters: [String: Any] = [:]
            parameters["token"] = token
            parameters["helpid"] = helpid

            return YSTargetRequest(path: RequestURL.stopAskForHelpAction,
                                   method: .post,
                                   parameters: parameters
            )
        case .terminatHelpAction(let token):
            var parameters: [String: Any] = [:]
            parameters["token"] = token
            return YSTargetRequest(path: RequestURL.terminatHelpAction,
                                   method: .post,
                                   parameters: parameters
            )
        case .startRouteAction(let token, let helpid):
            var parameters: [String: Any] = [:]
            parameters["token"] = token
            parameters["helpid"] = helpid

            return YSTargetRequest(path: RequestURL.startRouteAction,
                                   method: .post,
                                   parameters: parameters
            )
        case .stopRouteAction(let token, let helpid):
            var parameters: [String: Any] = [:]
            parameters["token"] = token
            parameters["helpid"] = helpid

            return YSTargetRequest(path: RequestURL.stopRouteAction,
                                   method: .post,
                                   parameters: parameters
            )
            
        case .commentAction(let token, let star, let content, let helpId):
            var parameters: [String: Any] = [:]
            parameters["token"] = token
            parameters["star"] = star
            parameters["content"] = content
            parameters["helpid"] = helpId

            return YSTargetRequest(path: RequestURL.commentAction,
                                   method: .post,
                                   parameters: parameters
            )
            

            
        }
        
        
    }
    
    public var path: String {
        return self.api.path
    }
    // 获取基本的url，每次发生地址变更时，替换这个url
    public var baseURL: URL {
        
        return self.api.baseURL ?? URL(string: HostManager.kMainHost)!
    }
    public var method: Moya.Method {
        return self.api.method
    }
    public var parameters: [String: Any]? {
        return self.api.parameters
    }
    public var sampleData: Data {
        return self.api.sampleData
    }
    public var task: Task {
        return self.api.task
    }
    public var validate: Bool {
        return false
    }
    public var parameterEncoding: Moya.ParameterEncoding {
        return self.api.parameterEncoding
    }
}
